package validation;

import java.lang.Character;

import dbmanager.DBManager;

public class Isalphanumeric implements Validation{
	
	
	public static void main (String args[])
	{
		Isalphanumeric ipn = new Isalphanumeric();
		
		System.out.println("Validate :"+ipn.validate("rt12"));
		
	}

	public String getMessage() 
	{
		return "Is Not Alpha Numeric ";
	}

	public boolean validate(String Value) 
	{
		int i=0;
		char chk;
		try
		{
			while (true)
			{
				if(i == Value.length()-1)
					return false;
				chk=Value.charAt(i);
				
				if (Character.isDigit(chk)== false)
				{
					if (Isspecialchar.validate(chk))
						return false;
					
					i++;
					continue;
				}
				else if (Character.isDigit(chk)== true)
				{
					for (int j=i+1; j<Value.length(); j++)
					{
						chk=Value.charAt(j);
						if (Character.isDigit(chk)== false)
						{
							return false;
						}
					}
					break;
				}
				else
					return false;
			}
		}
		catch (Exception e) 
		{
			return false;
		}
	return true;
	}								

	public boolean validate(String Value, String ConditionValue) {
		// TODO Auto-generated method stub
		return false;
	}

	public void setDbmanager(DBManager database) {
		// TODO Auto-generated method stub
		
	}

	public boolean validate(String Value, String ConditionValue, String Refvalue) 
	{	
		/*boolean tempboolean = validate(Value);
		
		if(ConditionValue.toLowerCase().equals("true"))
			return tempboolean;
		else
			return !tempboolean;
		*/
		if(ConditionValue.equalsIgnoreCase("true"))
		{
			return validate(Value);
		}
		else if(ConditionValue.equalsIgnoreCase("false"))
			return true;
		else
			return false;
	}

	public void setBasicvalue(String value) {
		// TODO Auto-generated method stub
		
	}

}
